Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Allow Zig structures to define a sub_type which will be included in the RemoteObject's subtype field (and will generate an empty description field)

External PersitedObjects now wrap our own ExternalEntry wrapper, which includes a pointer to the Zig instance (what we used to have before). This approach allows us to associate metadata with a v8.Value. We currently add the subtype if available.

Allow Zig structures to define a `sub_type` which will be included in the
RemoteObject's subtype field (and will generate an empty description field)

External PersitedObjects now wrap our own ExternalEntry wrapper, which includes
a pointer to the Zig instance (what we used to have before). This approach
allows us to associate metadata with a v8.Value. We currently add the subtype
if available.
@krichprollsch
Copy link
Member

I'm testing this PR with browser and I get a v8 error:

#
# Fatal error in v8::Object::GetInternalField()
# Internal field out of bounds
#

// the proper subtype (and description) fields in the returned JSON.
// V8 will give us a Value and ask us for the subtype. Hence, we store it
// here.
sub_type: ?[:0]const u8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we have a finite list of subtypes: https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
Maybe we could use an enum instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of subtypes is known, from Browser's point of view. But in zig-js-runtime, just like in V8 itself, it's an arbitrary application-specific value.

I did however change the type to ?[*c]const u8, which is what we actually need for the V8 interface and is 8 bytes smaller. With this change, the @sizeOf(ExternalEntry) is the same as-if we were using an enum (assuming padding). Also, this value is, always a string literal, so it's allocation-free.

Makes the @sizeof(ExternalEntry) 16, instead of 24 and works just as well
with the string literal we expect it to be set to.
@krichprollsch krichprollsch merged commit 5c23f1c into lightpanda-io:main Mar 31, 2025
9 checks passed
@karlseguin karlseguin deleted the remote_object_subtype branch April 3, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants